define(function (require, exports, module) {

    // 通过 require 引入依赖
    // var $ = require('jquery');
    require('common');
    require('sui');
    require('md5');
    var template = require('template');
    $('#form-password').validate({
        success: function () {
            updatePassword();
            return false;
        }
    });

    $('#form-bind').validate({
        success: function () {
            updateBind();
            return false;
        }
    });

    function updatePassword() {

        var password = $.md5($.trim($('#password').val()));
        var passwordOld = $.md5($.trim($('#password-old').val()));
        var data = {
            passwordOld: passwordOld,
            password: password
        };
        if (password == passwordOld) {
            toastInfo('新密码不能和原来的密码一样');
            return;
        }
        $('.update-password').prop('disabled', 'disabled');
        $.post('/userSet/updatePassword', data, function (o) {
            switch (o.code) {
                case 0:
                    toastSuccess('修改密码成功');
                    setTimeout(function () {
                        window.location.href = '/login'
                    }, 2000);
                    break;
                default:
                    toastError(o.msg);
                    $('.update-password').removeAttr('disabled');
            }
        })


    }

    function updateBind() {

        var mobil = $.trim($('#mobil').val());
        var email = $.trim($('#email').val());
        var data = {
            mobil: mobil,
            email: email
        };
        if (mobil == '' && email == '') {
            return;
        }
        $('.update-bind').prop('disabled', 'disabled');
        $.post('/userSet/updateBind', data, function (o) {
            switch (o.code) {
                case 0:
                    toastSuccess('修改绑定信息成功');
                    setTimeout(function () {
                        $('.update-bind').removeAttr('disabled');
                    }, 2000);
                    break;
                default:
                    toastError(o.msg);
                    $('.update-bind').removeAttr('disabled');
            }
        })


    }


});
